|
|
|
|
|
|
|
code must include information about which controls to use and where they should be placed on the page. |
|
|
|
|
|
|
|
|
To begin using VBScript in an HTML page, you must tell the browser which scripting language you'll be using. This is done by using the <Script></Script> tags, which define the script block in the Web page. For VBScript, the syntax in a Web page would start out as follows: |
|
|
|
|
|
|
|
|
<Script Language=VBScript>
·
·
</Script> |
|
|
|
|
|
|
|
|
Immediately after the <Script> statement, your VBScript code is added in an HTML comment block (<!- and -> tags) so that your code isn't displayed by browsers that don't support VBScript. At the end of the comment block, the closing </Script> tag tells the browser that there's no more code. Listing 14.1 shows a simple Web page that displays a message box every time the page is accessed. |
|
|
|
|
|
|
|
|
LISTING 14.1.HTMLDEMO1.HTMA SIMPLE WEB PAGE THAT DISPLAYS A VISUAL BASIC MESSAGE BOX. |
|
|
|
 |
|
|
|
|
<HTML>
<HEAD>
<SCRIPT LANGUAGE=VBScript>
<!--
MsgBox Hello World!
-->
</SCRIPT>
</HEAD>
</HTML> |
|
|
|
|
|
|
|
|
Although you can have code executed when the page is loaded, typically you would want to execute your code in response to an event, the same way as in Visual Basic. To do this, you need a control on the page that users can interact with and an event routine for that control. In Visual Basic, this is done for you when you place a command button on the form, and a Click event is created when you double-click the control. In VBScript, you must do everything yourself, but it isn't as difficult as it sounds. Listing 14.2 shows how to create a command button on the Web page and display a message box in response to the Click event. |
|
|
|
|
|